$(function(){

  const params = {
    page: 1,
    perpage:6,
  }
 list()

function list(){
  $.ajax({
    type: 'get',
    url: '/admin/comment/search',
    data: params,
    success: (backData) => {
        console.log(backData);
     let res= template('temp',backData)
     $('tbody').html(res)
     const totalCount=backData.data.totalCount        
          layerPager(totalCount)
    },
  })
 
}

function layerPager(totalCount) {
  layui.use('laypage', function () {
    var laypage = layui.laypage
    // 执行一个 laypage 分页实例
    laypage.render({
      elem: 'pager', // 注意，这里的 pager 是 ID，不用加 # 号
      count:totalCount, // 数据pagerpagerpager总数，从服务端得到
      limit:params.perpage,
      curr: params.page, 
      jump: function(obj, first){
        //obj包含了当前分页的所有参数，比如：
        console.log(obj.curr); //得到当前页，以便向服务端请求对应页的数据。
        console.log(obj.limit); //得到每页显示的条数
        params.page=obj.curr
        //首次不执行
        if(!first){
          list()
        }
      }
    })
  })
}
  
$('tbody').on('click','.pz',function(){
let id=$(this).attr('data-id')
$.ajax({
  type: 'post',
  url: '/admin/comment/pass',
  data: {id},
  success: (backData) => {
    if(backData.code==200){
      layer.msg(backData.msg)
    }
  },
})
})

$('tbody').on('click','.jj',function(){
  let id=$(this).attr('data-id')
  $.ajax({
    type: 'post',
    url: '/admin/comment/reject',
    data: {id},
    success: (backData) => {
      if(backData.code==200){
        layer.msg(backData.msg)
      }
    },
  })
  })
  $('tbody').on('click','.sc',function(){
    let id=$(this).attr('data-id')
    $.ajax({
      type: 'post',
      url: '/admin/comment/delete',
      data: {id},
      success: (backData) => {
        if(backData.code==200){
          layer.msg(backData.msg)
        }
      },
    })
    })
});
